import { Category_Child, Item } from "../../pages/category/category";

let tab: Array<Category_Child> = [];
let currentItem: Array<Item> = [];
let activeId = 0;
let cat_id = 0;
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    tab: Object,
  },

  /**
   * 组件的初始数据
   */
  data: {
    tab,
    currentItem,
    activeId,
    cat_id,
  },

  /**
   * 组件的方法列表
   */
  methods: {
    active_item(e: any) {
      const id = e.currentTarget.dataset.id as number;
      tab = this.data.tab;
      activeId = id;
      currentItem = tab.find((item) => item.cat_id === id)?.children || [];
      this.setData({ currentItem, activeId });
    },
    async tapItem(e: any) {
      const item = e.currentTarget.dataset.item as Item;
      wx.navigateTo({
        url: `/pages/goods_list/goods_list?query=${item.cat_name}`,
      });
    },
  },
  lifetimes: {
    attached() {},
  },
});
